
#include "Math.h"

#include "Types.h"

using namespace Iride;

void Math::Lerp(Real start, Real end, int numValues, Real * out)
{
	if (numValues > 1)
	{
		Real step = (end - start) / Real(numValues - 1);

		out[0] = start;

		Real acc = start;

		int numLoops = numValues - 1;

		for (int i = 1; i < numLoops; i++)
		{
			acc += step;
			out[i] = acc;
		}

		out[numValues-1] = end;
	}
	else
	{
		if (numValues == 1)
		{
			out[0] = ( start * 0.5) + ( end * 0.5);
		}
	}
}

// yOut length must be x2-x
void Math::GetLine(int x, int y, int x2, int y2, int * yOut)
{
	int yLength=y2-y;
	int xLength=x2-x;
	int index;

	int decInc;
	if (xLength==0)
	{
		decInc=0;
	}
	else
	{
		decInc = (yLength << 16) / xLength;
	}

	if (xLength > 0)
	{
		index = 0;
		for (int j=0x8000+(y<<16); index<=xLength; index++)
		{
			yOut[index] = (j >> 16);
			j+=decInc;
		}
		return;
	}

	index = 0;
	int top = - xLength;
	for (int j=0x8000 + (y<<16); index<=top; index++)
	{
		yOut[index] =  (j >> 16);
		j-=decInc;
	}

}

